#include "gtest/gtest.h"
#include "Bundle.h"

typedef struct {
    int i;
    char j;
} TestDataType;


TEST(BundleTest, BooleanTest) {
    Bundle b = newBundle();
    ASSERT_EQ(getBoolean(b, 0, TRUE), TRUE);
    ASSERT_EQ(getBoolean(b, 0, FALSE), FALSE);
 
    putBoolean(b, 0, TRUE);
    ASSERT_EQ(getBoolean(b, 0, FALSE), TRUE);
 
    putBoolean(b, 1, TRUE);
    ASSERT_EQ(getBoolean(b, 1, FALSE), TRUE);
    deleteBundle(b);
}

TEST(BundleTest, IntTest) {
    Bundle b = newBundle();
    ASSERT_EQ(getInt(b, 0, 1), 1);
    ASSERT_EQ(getInt(b, 0, 0), 0);
 
    putInt(b, 0, 1);
    ASSERT_EQ(getInt(b, 0, 0), 1);
 
    putInt(b, 1, 1);
    ASSERT_EQ(getInt(b, 1, 0), 1);
    deleteBundle(b);
}

TEST(BundleTest, StringTest) {
    Bundle b = newBundle();
    const char* defaultString = "hello";
    const char* test = getString(b, 0, defaultString);
    ASSERT_EQ(defaultString, test);

    const char* test1 = "world";
    putString(b, 0, test1);
    char* test2 = getString(b, 0, defaultString);
    ASSERT_EQ(memcmp(test1, test2, strlen(test1)), 0);
    deleteBundle(b);
}

TEST(BundleTest, ObjectTest) {
    Bundle b = newBundle();
    ASSERT_EQ(getObject(b, 0), (void*)NULL);
    TestDataType test = {10, '1'};
    putObject(b, 0, &test, sizeof(test));
    TestDataType* result = (TestDataType*)getObject(b, 0);
    ASSERT_NE(result, (TestDataType*)NULL);
    ASSERT_EQ(test.i, result->i);
    ASSERT_EQ(test.j, result->j);
    deleteBundle(b);
}

